package team.southcat.wsyygh.common.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.common.service.AreaService;
import team.southcat.wsyygh.model.pojo.common.Area;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author QiuSiYi
 * @since 2023-04-20
 */
@Api(tags = "区域地址管理接口")
@RestController
@RequestMapping("/admin/common/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    @ApiOperation("查询所有ParentId下的areas")
    @GetMapping("/getChildByParentId/{id}")
    public Result getChildByParentId(@PathVariable int id){
        List<Area> areas = areaService.getChildByParentId(id);
        return Result.ok(areas);
    }

    @ApiOperation("获取所有省份")
    @GetMapping("/getAllProvince")
    public Result getAllProvince(){
        List<Area> areas = areaService.getAllProvince();
        return Result.ok(areas);
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable int id){
        Area area = areaService.getById(id);
        return Result.ok(area);
    }

    //根据代码获取子数据
    @GetMapping("/findByAreaCode/{areaCode}")
    public Result findByAreaCode(@PathVariable String areaCode){
        List<Area> areas = areaService.findByAreaCode(areaCode);
        return Result.ok(areas);
    }
}

